package com.springboot.study.producer;

import com.springboot.study.config.DirectConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/direct")
public class DirectProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 根据日志级别发送消息到对应队列
     * URL: POST http://localhost:10001/direct/send?level=error&message=测试消息
     */
    @GetMapping("/send")
    public String sendByRouting(@RequestParam String level,
                                @RequestParam String message) {
        rabbitTemplate.convertAndSend(DirectConfig.DIRECT_EXCHANGE, level, message);
        return String.format("发送%s级别消息：%s", level, message);
    }
}
